﻿@using FwProject.PrePaymentInfo.Dto
@using X.PagedList
@model List<ReceiptDetailsDto>
@{
    ViewBag.Title = "收款详情";
}
@section styles{
    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Theme/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="~/Content/font-awesome.css" rel="stylesheet" />
    <link href="~/Theme/css/plugins/sweetalert/sweetalert.css" rel="stylesheet" />
    <style type="text/css">
        .input-group[class*=col-] {
            padding: 0 15px;
        }
    </style>
}
<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>@ViewBag.Title</h5>
                <div class="ibox-tools">
                    @if (IsGranted(FwProject.Authorization.PermissionNames.Finance_Operation_Payment))
                    {
                        <button id="btnPayment" class="btn btn-primary btn-xs">交账并打印收据</button>
                    }
                    else
                    {
                        <button type="button" class="btn btn-default btn-xs">无交账权限</button>
                    }
                </div>
            </div>
            <div class="ibox-content">
                <div class="row m-b-sm m-t-sm">
                    <form class="form-horizontal" id="form1" action="/Payment/ReceiptDetail?id=@ViewBag.Id" data-ajax="true" data-ajax-update="#data_list" data-ajax-method="Get" data-ajax-mode="replace">
                        <div class="col-md-2">
                            <label class="control-label col-md-3" style="width:90px">状态：</label>
                            <div class="input-group">
                                <select class="form-control" name="ReceiptInfoStatus">
                                    <option value="" selected>全部</option>
                                    <option value="0">未提交</option>
                                    <option value="1">已提交</option>
                                    <option value="2">已审核</option>
                                    <option value="3">退回</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-5">
                            <label class="control-label col-md-3" style="width:90px">日期：</label>
                            <div class="col-md-2">
                                <select id="data_select" class="input-s form-control"></select>
                            </div>
                            <div class="input-daterange input-group" id="datepicker">
                                <input type="text" name="beginTime" id="beginTime" placeholder="起始日期" class="input-sm form-control" autocomplete="off">
                                <span class="input-group-addon">至</span>
                                <input type="text" name="endTime" id="endTime" placeholder="结束日期" class="input-sm form-control" autocomplete="off" />
                            </div>
                        </div>
                        <div class="col-md-1">
                            <span class="input-group-btn">
                                <button type="submit" class="btn btn-sm btn-primary"> 查询</button>
                            </span>
                        </div>
                    </form>
                </div>
                <div id="data_list">
                    <form class="form-horizontal" id="PaymentingForm" asp-controller="Payment" asp-action="Paymenting" data-ajax="true" data-ajax-method="Post" data-ajax-success="openPrint">
                        @{Html.RenderPartial("ReceiptDetailPartial", Model);}
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="modal_ajax" class="modal inmodal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
</div>
@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/Theme/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="~/js/DateComm.js"></script>
    <script type="text/javascript">
        //layer.msg("test",{time:2000});
        $(document).ready(function () {
            $.getJSON("/Payment/GetAgentPeoperData").done(function (data) {
                CommonAjaxCallback(data, function () {
                    bindSuggest(data.result);
                    bindSuggest1(data.result);
                }, null);
            }).fail(function () {
                layer.msg('连接超时，获取经办人失败！', {
                    icon: 2,
                    time: 2000
                });
            });

            $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });

            $('#chkDiv').on('ifChecked', function (event) { //ifCreated 事件应该在插件初始化之前绑定

                $("#t tbody").find('.i-checks').iCheck('check');
            });
            $('#chkDiv').on('ifUnchecked', function (event) { //ifCreated 事件应该在插件初始化之前绑定

                $("#t tbody").find('.i-checks').iCheck('uncheck');
            });

            $('#modal_ajax').on('show.bs.modal', function (e) {
                $(this).addClass('loading');
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url) {
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                    $(this).load(url, function () {
                        $.validator.unobtrusive.parse(this); //$("#form_model_create").validate();
                        $("input[name='Member.Birthday']").datepicker({ todayBtn: "linked", keyboardNavigation: !1, forceParse: !1, calendarWeeks: !0, autoclose: !0 });
                        $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
                        $(this).removeClass('loading');
                    });
                }
            });
            $('#modal_ajax').on('hidden.bs.modal', function (e) {
                $(this).empty();
            });

            $('#modal_del,#modal_password_reset').on('show.bs.modal', function (e) {
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url)
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                $(this).find("form").attr("action", url);
            });
            $('#modal_del,#modal_password_reset').on('hidden.bs.modal', function (e) {
                $(this).find("form").attr("action", "");
            });

            //开始时间
            $('#beginTime').datepicker({
                todayBtn: "linked",
                autoclose: true,
                todayHighlight: true

            }).on('changeDate', function (e) {
                var startTime = e.date;
                $('#endTime').datepicker('setStartDate', startTime);
            });
            //结束时间：
            $('#endTime').datepicker({
                todayBtn: "linked",
                autoclose: true,
                todayHighlight: true

            }).on('changeDate', function (e) {
                var endTime = e.date;
                $('#beginTime').datepicker('setEndDate', endTime);
            });

            $('#btnPayment').on("click", function () {
                var t = $("#t tbody").find('input[type="checkbox"]');
                var ids = [];
                for (var i = 0; i < t.length; i++) {
                    if ($(t[i]).prop('checked')) {
                        ids.push($(t[i]).val());
                    }
                }
                if (ids.length == 0) {
                    layer.msg('请至少选择一条数据！！', {
                        icon: 2,
                        time: 2000
                    });
                    return false;
                } else {
                    $("#PaymentingForm").submit();
                }
            });

            //$('#btnPayment').click(function () {
            //    var t = $("#t tbody").find('input[type="checkbox"]');
            //    var url = '/Payment/Paymenting';
            //    var ids = [];
            //    for (var i = 0; i < t.length; i++) {
            //        if ($(t[i]).prop('checked')) {
            //            ids.push($(t[i]).val());
            //        }
            //    }
            //    if (ids.length == 0) {
            //        layer.msg('请至少选择一条数据！！', {
            //            icon: 2,
            //            time: 2000
            //        });
            //        return false;
            //    }
            //    swal({
            //        title: "您确定要交账吗？",
            //        text: "请确认！",
            //        type: "warning",
            //        showCancelButton: true,
            //        confirmButtonColor: "#DD6B55",
            //        confirmButtonText: "确认",
            //        closeOnConfirm: false
            //    }, function () {
            //        url = url + '&ids=' + ids.join('|');
            //        window.location.href = url;
            //        swal("交账成功！", "", "success");
            //        window.location.reload();
            //    });
            //});
        });

        function bindSuggest(data) {
            if ($("#dropdown-agentpeoperuserid") != undefined) {
                $role = $("#dropdown-agentpeoperuserid").bsSuggest({
                    effectiveFields: ["name"],
                    effectiveFieldsAlias: { "name": "姓名" },
                    searchFields: ["name"],
                    clearable: true,
                    getDataMethod: "data",
                    //url: "/Users/GetSuggestData?type=司机类型&keyword=",
                    data: { value: data },
                    idField: "id",
                    keyField: "name",
                }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword, data) {
                    $("#AgentPeoperUserId").val(data.id);
                    console.log('onSetSelectValue: ', keyword, data);
                }).on('onUnsetSelectValue', function () {
                    console.log('onUnsetSelectValue');
                });
            }
        }
        function blurEmpty() {
            var cityObj = $("#dropdown-agentpeoperuserid");
            var DriverId = $("#AgentPeoperUserId");
            if (cityObj.val() == "") {
                DriverId.attr("value", "");
            }
        }
        function bindSuggest1(data) {
            if ($("#dropdown-paymentperson") != undefined) {
                $role = $("#dropdown-paymentperson").bsSuggest({
                    effectiveFields: ["name"],
                    effectiveFieldsAlias: { "name": "姓名" },
                    searchFields: ["name"],
                    clearable: true,
                    getDataMethod: "data",
                    //url: "/Users/GetSuggestData?type=司机类型&keyword=",
                    data: { value: data },
                    idField: "id",
                    keyField: "name",
                }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword, data) {
                    $("#PaymentPerson").val(data.id);
                    console.log('onSetSelectValue: ', keyword, data);
                }).on('onUnsetSelectValue', function () {
                    console.log('onUnsetSelectValue');
                });
            }
        }
        function blurEmpty1() {
            var cityObj = $("#dropdown-paymentperson");
            var DriverId = $("#PaymentPerson");
            if (cityObj.val() == "") {
                DriverId.attr("value", "");
            }
        }
        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                window.location.reload();
            }, successInfo);
        }

        function openPrint(data, successInfo) {
            CommonAjaxCallback(data, function () {
                window.location.reload();
                window.open('/Payment/PaymentPrint/' + data.result);
            }, successInfo);

        }


        new DateContUtil({//【下拉日期】
            selectId: "data_select",//下拉框のID
            startDate: 'beginTime',//开始日期(不填默认search_startDateBase)
            endDate: 'endTime',//结束日期(不填默认search_endDateBase)
            defaultValue: '0',//本月
            selectedFun: function () {//选中后触发の方法
                $("#form1").submit();
            }
        });
    </script>
}
